#include "pch.h"
#include "memorystream.h"

static ObjectPool<MemoryStream> _g_objPool("MemoryStream");
//-------------------------------------------------------------------------------------
ObjectPool<MemoryStream>& MemoryStream::ObjPool()
{
	return _g_objPool;
}

//-------------------------------------------------------------------------------------
void MemoryStream::destroyObjPool()
{
	LogDebug("MemoryStream::destroyObjPool(): size {%d}.\n", 
		_g_objPool.size());

	_g_objPool.destroy();
}

//-------------------------------------------------------------------------------------
MemoryStream::SmartPoolObjectPtr MemoryStream::createSmartPoolObj()
{
	return SmartPoolObjectPtr(new SmartPoolObject<MemoryStream>(ObjPool().createObject(), _g_objPool));
}

//-------------------------------------------------------------------------------------
size_t MemoryStream::getPoolObjectBytes()
{
	size_t bytes = sizeof(rpos_) + sizeof(wpos_) + data_.capacity();
	return bytes;
}

//-------------------------------------------------------------------------------------
void MemoryStream::onReclaimObject()
{
	if(data_.capacity() > DEFAULT_SIZE * 2)
		data_.reserve(DEFAULT_SIZE);

	clear(false);
}



